﻿// Decompiled with JetBrains decompiler
// Type: XamlEditor.PatAdorner
// Assembly: XamlEditor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 2AF0471B-7BFE-4738-893B-A4F91E243353
// Assembly location: C:\Users\KasimGulcan\Desktop\Kosgeb\DynaCAD\Project\lib\XamlEditor.dll

using Pats;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;

namespace XamlEditor
{
    public class PatAdorner : Adorner
    {
        private Thumb Start;
        private Thumb End;
        private Button ChangeType;
        private Thumb Angle1;
        private Thumb Angle;
        private VisualCollection VisualChildren;

        protected override int VisualChildrenCount
        {
            get
            {
                return this.VisualChildren.Count;
            }
        }

        public PatAdorner(Pat AdornedElement)
            : base((UIElement)AdornedElement)
        {
            this.VisualChildren = new VisualCollection((Visual)this);
            this.Start = new Thumb();
            this.End = new Thumb();
            this.Angle = new Thumb();
            this.Angle1 = new Thumb();
            this.ChangeType = new Button();
            this.BuildAdorners();
            this.ThumbHandler();
        }

        private void BuildAdorners()
        {
            this.Start.Height = this.Start.Width = 10.0;
            this.Start.Opacity = 0.8;
            this.Start.Background = (Brush)new SolidColorBrush(Colors.Black);
            this.Start.Style = (Style)this.FindResource((object)"Arrow");
            this.VisualChildren.Add((Visual)this.Start);
            this.End.Height = this.End.Width = 10.0;
            this.End.Opacity = 0.8;
            this.End.Background = (Brush)new SolidColorBrush(Colors.Black);
            this.End.Style = (Style)this.FindResource((object)"Arrow");
            this.VisualChildren.Add((Visual)this.End);
            this.Angle1.Height = this.Angle1.Width = 10.0;
            this.Angle1.Opacity = 0.8;
            this.Angle1.Style = (Style)this.FindResource((object)"ThumbStyle");
            this.Angle.Height = this.Angle1.Width = 10.0;
            this.Angle.Opacity = 0.8;
            this.Angle.Style = (Style)this.FindResource((object)"ThumbStyle");
            this.ChangeType.Width = 10.0;
            this.ChangeType.Height = 10.0;
        }

        private void ThumbHandler()
        {
            this.Start.DragDelta += new DragDeltaEventHandler(this.StartDragDelta);
            this.End.DragDelta += new DragDeltaEventHandler(this.EndDragDelta);
            this.ChangeType.Click += new RoutedEventHandler(this.ChangeTypeClick);
        }

        private void ChangeTypeClick(object sender, RoutedEventArgs e)
        {
            Pat pat = this.AdornedElement as Pat;

            if (pat.PatTipi == null)
                pat.PatTipi = Pat.PatTipleri.Düğme_Arka;
            else if (pat.PatTipi == Pat.PatTipleri.Düğme_Arka)
                pat.PatTipi = Pat.PatTipleri.Düğme_İlik;
            else if (pat.PatTipi == Pat.PatTipleri.Düğme_İlik)
                pat.PatTipi = Pat.PatTipleri.İlik;

            else
            {
                if (pat.PatTipi != Pat.PatTipleri.İlik)
                    return;
                pat.PatTipi = Pat.PatTipleri.Düğme;
            }
        }

        private void StartDragDelta(object sender, DragDeltaEventArgs e)
        {
            Pat pat = this.AdornedElement as Pat;
            Point position = Mouse.GetPosition((IInputElement)((FrameworkElement)pat).Parent);
            pat.StartPoint = position;
            this.InvalidateVisual();
        }

        private void EndDragDelta(object sender, DragDeltaEventArgs e)
        {
            Pat pat = this.AdornedElement as Pat;
            Point position = Mouse.GetPosition((IInputElement)((FrameworkElement)pat).Parent);
            pat.EndPoint = position;
            this.InvalidateVisual();
        }

        protected override void OnRender(DrawingContext drawingContext)
        {
            Rect rect = new Rect(this.AdornedElement.DesiredSize);
            Pat pat = this.AdornedElement as Pat;
            SolidColorBrush solidColorBrush = new SolidColorBrush(Colors.Green);
            solidColorBrush.Opacity = 0.3;
            Pen pen = new Pen((Brush)solidColorBrush, 1.5);
            drawingContext.DrawRectangle((Brush)null, pen, new Rect(new Point(0.0, 0.0), new Point(((FrameworkElement)pat).Width, ((FrameworkElement)pat).Height)));
        }

        protected override Size ArrangeOverride(Size finalSize)
        {
            Pat pat = this.AdornedElement as Pat;
            this.Start.Arrange(new Rect(new Point(-20.0, -20.0), new Point(pat.StartPoint.X * 2.0 + 20.0, pat.StartPoint.Y * 2.0 + 20.0)));
            this.End.Arrange(new Rect(new Point(-20.0, -20.0), new Point(pat.EndPoint.X * 2.0 + 20.0, pat.EndPoint.Y * 2.0 + 20.0)));
            this.ChangeType.Arrange(new Rect(new Point(-60.0, -20.0), new Point(pat.StartPoint.X * 2.0 + 20.0, pat.StartPoint.Y * 2.0 + 20.0)));
            this.Angle1.Arrange(new Rect(new Point(-60.0, -60.0), new Point(pat.StartPoint.X * 2.0 + 20.0, pat.StartPoint.Y * 2.0 + 20.0)));
            this.Angle.Arrange(new Rect(new Point(-60.0, -90.0), new Point(pat.StartPoint.X * 2.0 + 20.0, pat.StartPoint.Y * 2.0 + 20.0)));
            return finalSize;
        }

        protected override Visual GetVisualChild(int index)
        {
            return this.VisualChildren[index];
        }
    }
}
